package com.endbd.purchase.manage.firm.control;

import com.endbd.feignapi.model.purchase.CFirm;
import com.endbd.feignapi.util.PageModel;
import com.endbd.feignapi.util.ResultMessage;
import com.endbd.purchase.manage.firm.model.FirmCondition;
import com.endbd.purchase.manage.firm.service.IFirmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/purchase")
@RestController
public class FirmAction {

    @Autowired
    private IFirmService firmService;

    @RequestMapping("/firmPage")
    public ResultMessage BrandPage(PageModel<CFirm> pageModel, FirmCondition fcon){
        PageModel<CFirm> brandPageModel = firmService.queryFirmPageByCondition(pageModel,fcon);
        ResultMessage msg = new ResultMessage();
        msg.setStatus("200");
        msg.setFlag(true);
        msg.setMsg("查询成功！");
        msg.setResultData(brandPageModel);
        return msg;
    }

    @RequestMapping("/firmName")
    public ResultMessage firmName(FirmCondition fcon){
        List<String> firmName=firmService.firmName(fcon);
        ResultMessage msg = new ResultMessage();
        msg.setStatus("200");
        msg.setFlag(true);
        msg.setMsg("查询成功！");
        msg.setResultData(firmName);
        return msg;
    }

    @RequestMapping("/addFirm")
    public ResultMessage addFirm(CFirm firm){
        firmService.addFirm(firm);
        ResultMessage msg = new ResultMessage();
        msg.setStatus("200");
        msg.setFlag(true);
        msg.setMsg("添加了"+firm.getFirmName()+"厂商");
        return msg;

    }

    @RequestMapping("/alterFirm")
    public ResultMessage alterFirm(CFirm firm){
        firmService.alterFirm(firm);
        ResultMessage msg = new ResultMessage();
        msg.setStatus("200");
        msg.setFlag(true);
        msg.setMsg("修改为"+firm.getFirmName()+"厂商");
        return msg;
    }

    @RequestMapping("/lorFirm")
    public ResultMessage lorFirm(FirmCondition fcon){
        firmService.lorFirm(fcon);
        ResultMessage msg = new ResultMessage();
        msg.setStatus("200");
        msg.setFlag(true);
        if (fcon.getStatus()==1){
            msg.setMsg("禁用了"+fcon.getFirmName()+"品牌");
        }else {
            msg.setMsg("恢复了"+fcon.getFirmName()+"品牌");
        }
        return msg;
    }

}
